/*
 * TextField.java
 *
 * Created on 30 de agosto de 2007, 04:41 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package ig.formato.util;

import java.util.Comparator;

/**
 *
 * @author jsanchez
 */
public class TextField implements Comparable {

    private String text = null;
    private Integer x = null;
    private Integer y = null;
    private Integer w = null;
    private Integer h = null;
    private Integer sizeText = null;
    private String justificacion = null;
    private String formato = null;
    private String classs = null;
    private Integer banda = null;
    private Integer idice = 0;
    private boolean border = true;
    private boolean negrilla = false;
    private String tomarDatoDe = "F";
    private boolean fullBorder = false;
    private String valor = null;
    private boolean estirar=true;

    public boolean isEstirar() {
        return estirar;
    }

    public void setEstirar(boolean estirar) {
        this.estirar = estirar;
    }

    
    /** Creates a new instance of TextField */
    public TextField() {
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public void setTextFijo(String text) {
        this.text = text;
    }

    public Integer getX() {
        return x;
    }

    public void setX(Integer x) {
        this.x = x;
    }

    public Integer getY() {
        return y;
    }

    public void setY(Integer y) {
        this.y = y;
    }

    public Integer getW() {
        return w;
    }

    public void setW(Integer w) {
        this.w = w;
    }

    public Integer getH() {
        return h;
    }

    public void setH(Integer h) {
        this.h = h;
    }

    public Integer getSizeText() {
        return sizeText;
    }

    public void setSizeText(Integer sizeText) {
        this.sizeText = sizeText;
    }

    public String getJustificacion() {
        return justificacion;
    }

    public void setJustificacion(String justificacion) {
        this.justificacion = justificacion;
    }

    public String getFormato() {
        return formato;
    }

    public void setFormato(String formato) {
        this.formato = formato;
    }

    public String getClasss() {
        return classs;
    }

    public void setClasss(String classs) {
        this.classs = classs;
    }

    public Integer getBanda() {
        return banda;
    }

    public void setBanda(Integer banda) {
        this.banda = banda;
    }

    public int compareTo(Object o) {
        return this.getIdice().compareTo(((TextField) o).getIdice());
    }

    public Integer getIdice() {
        return idice;
    }

    public void setIdice(Integer idice) {
        this.idice = idice;
    }

    @Override
    public String toString() {
        StringBuilder textField = new StringBuilder("");

        if (this.formato == null) {
            textField.append("<textField isStretchWithOverflow=\"false\" isBlankWhenNull=\"true\" evaluationTime=\"Now\" hyperlinkType=\"None\"  hyperlinkTarget=\"Self\" >\n");
        } else {
            textField.append("<textField isStretchWithOverflow=\"false\" pattern=\"" + this.formato + "\" isBlankWhenNull=\"true\" evaluationTime=\"Now\" hyperlinkType=\"None\"  hyperlinkTarget=\"Self\" >\n");
        }
        textField.append("				<reportElement\n");
        textField.append("					x=\"" + x + "\"\n");
        textField.append("					y=\"" + y + "\"\n");
        textField.append("					width=\"" + w + "\"\n");
        textField.append("					height=\"" + h + "\"\n");
        textField.append("					forecolor=\"#000000\"\n");
        textField.append("					key=\"textField-1\"/>\n");
        String LINEA = this.fullBorder ? "1Point" : "None";
        if (border) {
            textField.append("				<box topBorder=\"None\" topBorderColor=\"#000000\" leftBorder=\"Thin\" leftBorderColor=\"#000000\" rightBorder=\"" + LINEA + "\" rightBorderColor=\"#000000\" bottomBorder=\"Thin\" bottomBorderColor=\"#000000\"/>\n");
        } else {
            textField.append("				<box topBorder=\"None\" topBorderColor=\"#000000\" leftBorder=\"None\" leftBorderColor=\"#000000\" rightBorder=\"None\" rightBorderColor=\"#000000\" bottomBorder=\"None\" bottomBorderColor=\"#000000\"/>\n");
        }
        if (this.justificacion == null) {
            textField.append("				<textElement  verticalAlignment=\"Middle\">\n");
        } else {
            textField.append("				<textElement textAlignment=\"" + this.justificacion + "\" verticalAlignment=\"Middle\">\n");
        }

        textField.append("					<font pdfFontName=\"Helvetica-Bold\" size=\"" + this.sizeText + "\" isBold=\"" + negrilla + "\"/>\n");
        textField.append("				</textElement>\n");

        if (this.classs.equals("java.lang.String") && this.valor == null) {
            //textField.append("			<textFieldExpression class=\"" + this.classs + "\"><![CDATA[\" \"+$" + tomarDatoDe + "{" + this.text + "}]]></textFieldExpression>\n");
            textField.append("			<textFieldExpression class=\"" + this.classs + "\"><![CDATA[$" + tomarDatoDe + "{" + this.text + "}]]></textFieldExpression>\n");
        } else if (this.classs.equals("java.lang.String") && this.valor != null) {
            textField.append("			<textFieldExpression class=\"" + this.classs + "\"><![CDATA[" + this.valor + "]]></textFieldExpression>\n");
        } else {
            textField.append("			<textFieldExpression class=\"" + this.classs + "\"><![CDATA[$" + tomarDatoDe + "{" + this.text + "}]]></textFieldExpression>\n");
        }
        textField.append("			</textField>\n");
        return textField.toString();
    }

    void setBorder(boolean border) {
        this.border = border;
    }

    void setNegrilla(boolean negrilla) {
        this.negrilla = negrilla;
    }

    public String getTomarDatoDe() {
        return tomarDatoDe;
    }

    public void setTomarDatoDe(String tomarDatoDe) {
        this.tomarDatoDe = tomarDatoDe;
    }

    void setFullBorder(boolean b) {
        this.fullBorder = b;
    }

    void setValor(String valor) {
        this.valor = valor;
    }
}
